package com.juc.threadPoolExecutor.threadPoolExecutor15.discardPolicy;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Run {

	/**
	 * DiscardPolicy:当任务添加到线程池中被拒绝时，线程池将丢弃被拒绝的任务
	 * @throws InterruptedException 
	 */
	public static void main(String[] args) throws InterruptedException {
		Runnable runnable =  new Runnable() {
			
			@Override
			public void run() {
				try {
					Thread.sleep(5000);
					System.out.println(Thread.currentThread().getName() + " run end !");
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
			}
		};
		ArrayBlockingQueue<Runnable> queue = new ArrayBlockingQueue<>(2);
		ThreadPoolExecutor executor = new ThreadPoolExecutor(2, 3, 5, TimeUnit.SECONDS, queue, new ThreadPoolExecutor.DiscardPolicy());
		executor.execute(runnable);
		executor.execute(runnable);
		executor.execute(runnable);
		executor.execute(runnable);
		executor.execute(runnable);
		executor.execute(runnable);
		executor.execute(runnable);
		executor.execute(runnable);
		Thread.sleep(8000);
		System.out.println(executor.getPoolSize() + "    " + queue.size());
	}
}
